package org.example.springbook.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.example.springbook.model.BookInfo;
import org.example.springbook.model.PageRequest;


import java.util.List;

@Mapper
public interface BookMapper {
    @Insert(" insert into book_info(book_name,author,count,price,publish,status)" +
            "values (#{bookName},#{author},#{count},#{price},#{publish},#{status})")
    Integer insertBook(BookInfo bookInfo);

    /**
     * 开始查询图书列表，查询的时候只查询状态不为零的，因为在删除的时候，只是运用了逻辑删除
     * 并没有进行删除数据，只是将他们显示不见了
     */
    @Select("select * from book_info where `status` <> 0 order by id desc limit #{offset},#{pageSize}")
    List<BookInfo> queryListBypage(PageRequest pageRequest);

    @Select(" select count(1) from book_info where `status` <> 0")
    Integer getCount();

    @Select("select * from book_info where id=#{id}")
    BookInfo queryBookById(@Param("id") Integer id);


    Integer updateBook(BookInfo bookInfo);

    //如果这里写的数组的话，还要进行转化成列表
    //在控制层的时候，还要注意一些细节的问题
    Integer batchDelete(List<Integer> ids);
}
